#include <wx/artprov.h>
#include <wx/bitmap.h>
#include <wx/settings.h>
#include <wx/font.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>

#include <wx/app.h>
#include <wx/msgdlg.h>
#include <wx/clrpicker.h>
#include <wx/dcmemory.h>
#include <wx/sstream.h>
#include <wx/tokenzr.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#include "../wxsitemresdata.h"
#include "../wxstool.h"

#include "wxsimagelisteditordlg.h"
#include "../wxsitem.h"



const wxChar fillchar = '=';
static wxString     cvt = _T( "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "abcdefghijklmnopqrstuvwxyz"
                              "0123456789+/" );


const long wxsImageListEditorDlg::ID_STATICTEXT1 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT15 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT16 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT17 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT18 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT26 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT19 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT27 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON1 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL2 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT2 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL3 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT3 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL4 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT4 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL5 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT5 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL8 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT6 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL6 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT7 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL7 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT8 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL9 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT9 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL10 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT10 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL11 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT12 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON2 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT11 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL1 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT23 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON5 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT20 = wxNewId();
const long wxsImageListEditorDlg::ID_CHECKBOX1 = wxNewId();
const long wxsImageListEditorDlg::ID_BUTTON2 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT21 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON3 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT13 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT22 = wxNewId();
const long wxsImageListEditorDlg::ID_PANEL12 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT28 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON4 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT14 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON6 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT24 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON7 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT25 = wxNewId();
const long wxsImageListEditorDlg::ID_BITMAPBUTTON8 = wxNewId();
const long wxsImageListEditorDlg::ID_STATICTEXT29 = wxNewId();
const long wxsImageListEditorDlg::ID_BUTTON1 = wxNewId();
const long wxsImageListEditorDlg::ID_BUTTON4 = wxNewId();

BEGIN_EVENT_TABLE( wxsImageListEditorDlg, wxScrollingDialog )
END_EVENT_TABLE()

wxsImageListEditorDlg::wxsImageListEditorDlg( wxWindow *parent ) {
  wxBoxSizer* BoxSizer4;
  wxStaticBoxSizer* StaticBoxSizer2;
  wxBoxSizer* BoxSizer6;
  wxBoxSizer* BoxSizer19;
  wxBoxSizer* BoxSizer15;
  wxBoxSizer* BoxSizer20;
  wxBoxSizer* BoxSizer5;
  wxBoxSizer* BoxSizer10;
  wxBoxSizer* BoxSizer7;
  wxBoxSizer* BoxSizer8;
  wxBoxSizer* BoxSizer13;
  wxBoxSizer* BoxSizer23;
  wxBoxSizer* BoxSizer2;
  wxBoxSizer* BoxSizer11;
  wxBoxSizer* BoxSizer16;
  wxBoxSizer* BoxSizer18;
  wxBoxSizer* BoxSizer12;
  wxBoxSizer* BoxSizer28;
  wxBoxSizer* BoxSizer14;
  wxStaticBoxSizer* StaticBoxSizer3;
  wxBoxSizer* BoxSizer27;
  wxBoxSizer* BoxSizer17;
  wxBoxSizer* BoxSizer24;
  wxBoxSizer* BoxSizer26;
  wxBoxSizer* BoxSizer32;
  wxBoxSizer* BoxSizer1;
  wxBoxSizer* BoxSizer9;
  wxStaticBoxSizer* StaticBoxSizer1;
  wxBoxSizer* BoxSizer34;
  wxBoxSizer* BoxSizer33;
  wxBoxSizer* BoxSizer3;
  wxBoxSizer* BoxSizer25;
  Create( parent, wxID_ANY, _T( "wxImageList Editor" ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T( "wxID_ANY" ) );
  SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
  wxFont thisFont( 8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _T( "Arial" ), wxFONTENCODING_DEFAULT );
  SetFont( thisFont );
  BoxSizer1 = new wxBoxSizer( wxVERTICAL );
  StaticBoxSizer2 = new wxStaticBoxSizer( wxVERTICAL, this, _T( "Image List" ) );
  BoxSizer2 = new wxBoxSizer( wxHORIZONTAL );
  StaticText14 = new wxStaticText( this, ID_STATICTEXT1, _T( "Name" ), wxPoint( 8, 20 ), wxSize( 38, 18 ), 0, _T( "ID_STATICTEXT1" ) );
  BoxSizer2->Add( StaticText14, 0, wxALIGN_BOTTOM, 5 );
  StaticText15 = new wxStaticText( this, ID_STATICTEXT15, _T( "Label" ), wxPoint( 40, 20 ), wxSize( 96, 18 ), wxST_NO_AUTORESIZE | wxSUNKEN_BORDER, _T( "ID_STATICTEXT15" ) );
  BoxSizer2->Add( StaticText15, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticText16 = new wxStaticText( this, ID_STATICTEXT16, _T( "Image Count" ), wxPoint( 144, 20 ), wxSize( -1, 18 ), 0, _T( "ID_STATICTEXT16" ) );
  BoxSizer2->Add( StaticText16, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticText17 = new wxStaticText( this, ID_STATICTEXT17, _T( "Label" ), wxPoint( 208, 20 ), wxSize( 32, 18 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE | wxSUNKEN_BORDER, _T( "ID_STATICTEXT17" ) );
  BoxSizer2->Add( StaticText17, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticText18 = new wxStaticText( this, ID_STATICTEXT18, _T( "Image Size" ), wxPoint( 248, 20 ), wxSize( -1, 18 ), 0, _T( "ID_STATICTEXT18" ) );
  BoxSizer2->Add( StaticText18, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticText26 = new wxStaticText( this, ID_STATICTEXT26, _T( "16" ), wxPoint( 304, 20 ), wxSize( 32, 18 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE | wxSUNKEN_BORDER, _T( "ID_STATICTEXT26" ) );
  BoxSizer2->Add( StaticText26, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticText19 = new wxStaticText( this, ID_STATICTEXT19, _T( "x" ), wxPoint( 344, 20 ), wxSize( -1, 18 ), 0, _T( "ID_STATICTEXT19" ) );
  BoxSizer2->Add( StaticText19, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticText27 = new wxStaticText( this, ID_STATICTEXT27, _T( "16" ), wxPoint( 360, 20 ), wxSize( 32, 18 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE | wxSUNKEN_BORDER, _T( "ID_STATICTEXT27" ) );
  BoxSizer2->Add( StaticText27, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  StaticBoxSizer2->Add( BoxSizer2, 0, wxALIGN_LEFT, 5 );
  BoxSizer5 = new wxBoxSizer( wxHORIZONTAL );
  BoxSizer6 = new wxBoxSizer( wxHORIZONTAL );
  bLeft = new wxBitmapButton( this, ID_BITMAPBUTTON1, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_GO_BACK" ) ), wxART_BUTTON ), wxPoint( 8, 52 ), wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON1" ) );
  bLeft->SetDefault();
  BoxSizer6->Add( bLeft, 0, wxALIGN_CENTER_VERTICAL, 0 );
  BoxSizer5->Add( BoxSizer6, 0, wxALIGN_TOP, 5 );
  BoxSizer7 = new wxBoxSizer( wxVERTICAL );
  Panel2 = new wxPanel( this, ID_PANEL2, wxPoint( 40, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL2" ) );
  Panel2->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer7->Add( Panel2, 0, wxALIGN_LEFT, 0 );
  StaticText2 = new wxStaticText( this, ID_STATICTEXT2, _T( "1" ), wxPoint( 40, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT2" ) );
  BoxSizer7->Add( StaticText2, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer7, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer8 = new wxBoxSizer( wxVERTICAL );
  Panel3 = new wxPanel( this, ID_PANEL3, wxPoint( 72, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL3" ) );
  Panel3->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer8->Add( Panel3, 0, wxALIGN_LEFT, 0 );
  StaticText3 = new wxStaticText( this, ID_STATICTEXT3, _T( "2" ), wxPoint( 72, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT3" ) );
  BoxSizer8->Add( StaticText3, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer8, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer9 = new wxBoxSizer( wxVERTICAL );
  Panel4 = new wxPanel( this, ID_PANEL4, wxPoint( 104, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL4" ) );
  Panel4->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer9->Add( Panel4, 0, wxALIGN_LEFT, 0 );
  StaticText4 = new wxStaticText( this, ID_STATICTEXT4, _T( "3" ), wxPoint( 104, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT4" ) );
  BoxSizer9->Add( StaticText4, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer9, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer10 = new wxBoxSizer( wxVERTICAL );
  Panel5 = new wxPanel( this, ID_PANEL5, wxPoint( 136, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL5" ) );
  Panel5->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer10->Add( Panel5, 0, wxALIGN_LEFT, 0 );
  StaticText5 = new wxStaticText( this, ID_STATICTEXT5, _T( "4" ), wxPoint( 136, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT5" ) );
  BoxSizer10->Add( StaticText5, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer10, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer11 = new wxBoxSizer( wxVERTICAL );
  Panel8 = new wxPanel( this, ID_PANEL8, wxPoint( 168, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL8" ) );
  Panel8->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer11->Add( Panel8, 0, wxALIGN_LEFT, 0 );
  StaticText6 = new wxStaticText( this, ID_STATICTEXT6, _T( "5" ), wxPoint( 168, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT6" ) );
  BoxSizer11->Add( StaticText6, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer11, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer12 = new wxBoxSizer( wxVERTICAL );
  Panel6 = new wxPanel( this, ID_PANEL6, wxPoint( 200, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL6" ) );
  Panel6->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer12->Add( Panel6, 0, wxALIGN_LEFT, 0 );
  StaticText7 = new wxStaticText( this, ID_STATICTEXT7, _T( "6" ), wxPoint( 200, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT7" ) );
  BoxSizer12->Add( StaticText7, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer12, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer13 = new wxBoxSizer( wxVERTICAL );
  Panel7 = new wxPanel( this, ID_PANEL7, wxPoint( 232, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL7" ) );
  Panel7->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer13->Add( Panel7, 0, wxALIGN_LEFT, 0 );
  StaticText8 = new wxStaticText( this, ID_STATICTEXT8, _T( "7" ), wxPoint( 232, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT8" ) );
  BoxSizer13->Add( StaticText8, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer13, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer14 = new wxBoxSizer( wxVERTICAL );
  Panel9 = new wxPanel( this, ID_PANEL9, wxPoint( 264, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL9" ) );
  Panel9->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer14->Add( Panel9, 0, wxALIGN_LEFT, 0 );
  StaticText9 = new wxStaticText( this, ID_STATICTEXT9, _T( "8" ), wxPoint( 264, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT9" ) );
  BoxSizer14->Add( StaticText9, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer14, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer15 = new wxBoxSizer( wxVERTICAL );
  Panel10 = new wxPanel( this, ID_PANEL10, wxPoint( 296, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL10" ) );
  Panel10->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer15->Add( Panel10, 0, wxALIGN_LEFT, 0 );
  StaticText10 = new wxStaticText( this, ID_STATICTEXT10, _T( "9" ), wxPoint( 296, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT10" ) );
  BoxSizer15->Add( StaticText10, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer15, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer16 = new wxBoxSizer( wxVERTICAL );
  Panel11 = new wxPanel( this, ID_PANEL11, wxPoint( 328, 48 ), wxSize( 32, 32 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL11" ) );
  Panel11->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer16->Add( Panel11, 0, wxALIGN_LEFT, 0 );
  StaticText12 = new wxStaticText( this, ID_STATICTEXT12, _T( "10" ), wxPoint( 328, 80 ), wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT12" ) );
  BoxSizer16->Add( StaticText12, 0, wxALL | wxEXPAND, 0 );
  BoxSizer5->Add( BoxSizer16, 0, wxALIGN_BOTTOM, 0 );
  BoxSizer17 = new wxBoxSizer( wxHORIZONTAL );
  bRight = new wxBitmapButton( this, ID_BITMAPBUTTON2, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_GO_FORWARD" ) ), wxART_BUTTON ), wxPoint( 368, 52 ), wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON2" ) );
  bRight->SetDefault();
  BoxSizer17->Add( bRight, 0, wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer5->Add( BoxSizer17, 0, wxALIGN_TOP, 5 );
  StaticBoxSizer2->Add( BoxSizer5, 1, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  BoxSizer1->Add( StaticBoxSizer2, 0, wxEXPAND, 5 );
  BoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
  StaticBoxSizer1 = new wxStaticBoxSizer( wxHORIZONTAL, this, _T( "Import from file" ) );
  BoxSizer18 = new wxBoxSizer( wxVERTICAL );
  StaticText1 = new wxStaticText( this, ID_STATICTEXT11, _T( "Imported Image" ), wxPoint( 8, 124 ), wxSize( 92, 16 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT11" ) );
  BoxSizer18->Add( StaticText1, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
  Panel1 = new wxPanel( this, ID_PANEL1, wxPoint( 8, 144 ), wxSize( 92, 92 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL1" ) );
  Panel1->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HOTLIGHT ) );
  Panel1->SetToolTip( _T( "Click any spot on the image to select a transparent color" ) );
  BoxSizer18->Add( Panel1, 1, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  StaticText23 = new wxStaticText( this, ID_STATICTEXT23, _T( "Label" ), wxPoint( 8, 240 ), wxSize( 92, 14 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT23" ) );
  BoxSizer18->Add( StaticText23, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  StaticBoxSizer1->Add( BoxSizer18, 0, wxEXPAND, 5 );
  BoxSizer19 = new wxBoxSizer( wxVERTICAL );
  BoxSizer23 = new wxBoxSizer( wxHORIZONTAL );
  bRead = new wxBitmapButton( this, ID_BITMAPBUTTON5, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_OPEN" ) ), wxART_BUTTON ), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON5" ) );
  bRead->SetDefault();
  BoxSizer23->Add( bRead, 0, wxALIGN_BOTTOM, 0 );
  StaticText20 = new wxStaticText( this, ID_STATICTEXT20, _T( "Read File" ), wxPoint( 136, 148 ), wxDefaultSize, 0, _T( "ID_STATICTEXT20" ) );
  BoxSizer23->Add( StaticText20, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer19->Add( BoxSizer23, 0, wxEXPAND, 5 );
  BoxSizer24 = new wxBoxSizer( wxHORIZONTAL );
  cxTransparent = new wxCheckBox( this, ID_CHECKBOX1, _T( "Transparent" ), wxPoint( 108, 174 ), wxDefaultSize, 0, wxDefaultValidator, _T( "ID_CHECKBOX1" ) );
  cxTransparent->SetValue( false );
  BoxSizer24->Add( cxTransparent, 0, wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer19->Add( BoxSizer24, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer25 = new wxBoxSizer( wxHORIZONTAL );
  bColor = new wxButton( this, ID_BUTTON2, _T( "C" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T( "ID_BUTTON2" ) );
  wxFont bColorFont( 10, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_BOLD, false, _T( "Sans" ), wxFONTENCODING_DEFAULT );
  bColor->SetFont( bColorFont );
  BoxSizer25->Add( bColor, 0, wxALIGN_BOTTOM, 0 );
  StaticText21 = new wxStaticText( this, ID_STATICTEXT21, _T( "Mask Color" ), wxPoint( 136, 200 ), wxDefaultSize, 0, _T( "ID_STATICTEXT21" ) );
  BoxSizer25->Add( StaticText21, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer19->Add( BoxSizer25, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer26 = new wxBoxSizer( wxHORIZONTAL );
  bAdd = new wxBitmapButton( this, ID_BITMAPBUTTON3, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_ADD_BOOKMARK" ) ), wxART_BUTTON ), wxPoint( 104, 220 ), wxDefaultSize, wxBU_LEFT | wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON3" ) );
  BoxSizer26->Add( bAdd, 0, wxALIGN_BOTTOM, 0 );
  StaticText11 = new wxStaticText( this, ID_STATICTEXT13, _T( "Add To List" ), wxPoint( 136, 224 ), wxDefaultSize, 0, _T( "ID_STATICTEXT13" ) );
  BoxSizer26->Add( StaticText11, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer19->Add( BoxSizer26, 0, wxTOP | wxEXPAND, 5 );
  StaticBoxSizer1->Add( BoxSizer19, 0, wxLEFT | wxEXPAND, 5 );
  BoxSizer3->Add( StaticBoxSizer1, 1, wxEXPAND, 5 );
  StaticBoxSizer3 = new wxStaticBoxSizer( wxHORIZONTAL, this, _T( "Options" ) );
  BoxSizer27 = new wxBoxSizer( wxVERTICAL );
  StaticText22 = new wxStaticText( this, ID_STATICTEXT22, _T( "Selected Image" ), wxPoint( 208, 124 ), wxSize( 92, 16 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT22" ) );
  BoxSizer27->Add( StaticText22, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
  Panel12 = new wxPanel( this, ID_PANEL12, wxPoint( 208, 144 ), wxSize( 92, 92 ), wxDOUBLE_BORDER | wxTAB_TRAVERSAL, _T( "ID_PANEL12" ) );
  Panel12->SetBackgroundColour( wxColour( 220, 220, 220 ) );
  BoxSizer27->Add( Panel12, 1, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  StaticText28 = new wxStaticText( this, ID_STATICTEXT28, _T( "Label" ), wxPoint( 208, 240 ), wxSize( 88, 14 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT28" ) );
  BoxSizer27->Add( StaticText28, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5 );
  StaticBoxSizer3->Add( BoxSizer27, 0, wxEXPAND, 5 );
  BoxSizer28 = new wxBoxSizer( wxVERTICAL );
  BoxSizer32 = new wxBoxSizer( wxHORIZONTAL );
  bDel = new wxBitmapButton( this, ID_BITMAPBUTTON4, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_DEL_BOOKMARK" ) ), wxART_BUTTON ), wxPoint( 304, 144 ), wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON4" ) );
  bDel->SetDefault();
  BoxSizer32->Add( bDel, 0, wxALIGN_BOTTOM, 0 );
  StaticText13 = new wxStaticText( this, ID_STATICTEXT14, _T( "Delete Image" ), wxPoint( 336, 148 ), wxDefaultSize, 0, _T( "ID_STATICTEXT14" ) );
  BoxSizer32->Add( StaticText13, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer28->Add( BoxSizer32, 0, wxEXPAND, 5 );
  BoxSizer33 = new wxBoxSizer( wxHORIZONTAL );
  bClear = new wxBitmapButton( this, ID_BITMAPBUTTON6, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_DELETE" ) ), wxART_BUTTON ), wxPoint( 304, 174 ), wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON6" ) );
  bClear->SetDefault();
  BoxSizer33->Add( bClear, 0, wxALIGN_BOTTOM, 0 );
  StaticText24 = new wxStaticText( this, ID_STATICTEXT24, _T( "Clear List" ), wxPoint( 336, 178 ), wxDefaultSize, 0, _T( "ID_STATICTEXT24" ) );
  BoxSizer33->Add( StaticText24, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer28->Add( BoxSizer33, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer34 = new wxBoxSizer( wxHORIZONTAL );
  bSave = new wxBitmapButton( this, ID_BITMAPBUTTON7, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_SAVE" ) ), wxART_BUTTON ), wxPoint( 304, 204 ), wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON7" ) );
  bSave->SetDefault();
  BoxSizer34->Add( bSave, 0, wxALIGN_BOTTOM, 0 );
  StaticText25 = new wxStaticText( this, ID_STATICTEXT25, _T( "Export selected BMP" ), wxPoint( 336, 208 ), wxDefaultSize, 0, _T( "ID_STATICTEXT25" ) );
  BoxSizer34->Add( StaticText25, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer28->Add( BoxSizer34, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer20 = new wxBoxSizer( wxHORIZONTAL );
  bSaveList = new wxBitmapButton( this, ID_BITMAPBUTTON8, wxArtProvider::GetBitmap( wxART_MAKE_ART_ID_FROM_STR( _T( "wxART_FILE_SAVE_AS" ) ), wxART_BUTTON ), wxPoint( 304, 204 ), wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_BITMAPBUTTON8" ) );
  bSaveList->SetDefault();
  BoxSizer20->Add( bSaveList, 0, wxALIGN_BOTTOM, 0 );
  StaticText29 = new wxStaticText( this, ID_STATICTEXT29, _T( "Export list as BMP" ), wxPoint( 336, 208 ), wxDefaultSize, 0, _T( "ID_STATICTEXT29" ) );
  BoxSizer20->Add( StaticText29, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer28->Add( BoxSizer20, 0, wxTOP | wxEXPAND, 5 );
  StaticBoxSizer3->Add( BoxSizer28, 0, wxLEFT | wxEXPAND, 5 );
  BoxSizer3->Add( StaticBoxSizer3, 1, wxLEFT | wxEXPAND, 5 );
  BoxSizer1->Add( BoxSizer3, 0, wxEXPAND, wxDLG_UNIT( this, wxSize( 5, 0 ) ).GetWidth() );
  BoxSizer4 = new wxBoxSizer( wxHORIZONTAL );
  bOK = new wxButton( this, ID_BUTTON1, _T( "OK" ), wxPoint( 72, 280 ), wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON1" ) );
  bOK->SetDefault();
  BoxSizer4->Add( bOK, 0, wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer4->Add( -1, -1, 1, wxALIGN_CENTER_VERTICAL, 5 );
  bCancel = new wxButton( this, ID_BUTTON4, _T( "Cancel" ), wxPoint( 256, 280 ), wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON4" ) );
  BoxSizer4->Add( bCancel, 0, wxALIGN_CENTER_VERTICAL, 5 );
  BoxSizer1->Add( BoxSizer4, 0, wxTOP | wxEXPAND, 5 );
  SetSizer( BoxSizer1 );
  ColourDialog1 = new wxColourDialog( this );
  FileDialog1 = new wxFileDialog( this, _T( "Select output file" ), wxEmptyString, wxEmptyString, _T( "Bitmap Files|*.bmp|All Files|*.*" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, _T( "wxFileDialog" ) );
  BoxSizer1->Fit( this );
  BoxSizer1->SetSizeHints( this );
  Connect( ID_BITMAPBUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbLeftClick ) );
  Panel2->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel2->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel2LeftUp ), 0, this );
  Panel3->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel3->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel3LeftUp ), 0, this );
  Panel4->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel4->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel4LeftUp ), 0, this );
  Panel5->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel5->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel5LeftUp ), 0, this );
  Panel8->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel8->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel8LeftUp ), 0, this );
  Panel6->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel6->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel6LeftUp ), 0, this );
  Panel7->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel7->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel7LeftUp ), 0, this );
  Panel9->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel9->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel9LeftUp ), 0, this );
  Panel10->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel10->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel10LeftUp ), 0, this );
  Panel11->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::PaintPreviewPanel ), 0, this );
  Panel11->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel11LeftUp ), 0, this );
  Connect( ID_BITMAPBUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbRightClick ) );
  Panel1->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::OnPanel1Paint ), 0, this );
  Panel1->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxsImageListEditorDlg::OnPanel1LeftUp ), 0, this );
  Connect( ID_BITMAPBUTTON5, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbReadClick ) );
  Connect( ID_CHECKBOX1, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OncxTransparentClick ) );
  Connect( ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbColorClick ) );
  Connect( ID_BITMAPBUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbAddClick ) );
  Panel12->Connect( wxEVT_PAINT, wxPaintEventHandler( wxsImageListEditorDlg::OnPanel12Paint ), 0, this );
  Connect( ID_BITMAPBUTTON4, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbDelClick ) );
  Connect( ID_BITMAPBUTTON6, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbClearClick ) );
  Connect( ID_BITMAPBUTTON7, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbSaveClick ) );
  Connect( ID_BITMAPBUTTON8, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbSaveListClick ) );
  Connect( ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbOKClick ) );
  Connect( ID_BUTTON4, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageListEditorDlg::OnbCancelClick ) );
  wxInitAllImageHandlers();
  m_ImageDialog   = new wxsBitmapIconEditorDlg( 0, m_ImageData, _T( "wxART_OTHER" ) );
  m_ImportMask    = *wxWHITE;
  m_FirstImage    = 0;
  m_PreviewSelect = -1;
  m_PreviewPanel[0] = Panel2;
  m_PreviewLabel[0] = StaticText2;
  m_PreviewPanel[1] = Panel3;
  m_PreviewLabel[1] = StaticText3;
  m_PreviewPanel[2] = Panel4;
  m_PreviewLabel[2] = StaticText4;
  m_PreviewPanel[3] = Panel5;
  m_PreviewLabel[3] = StaticText5;
  m_PreviewPanel[4] = Panel8;
  m_PreviewLabel[4] = StaticText6;
  m_PreviewPanel[5] = Panel6;
  m_PreviewLabel[5] = StaticText7;
  m_PreviewPanel[6] = Panel7;
  m_PreviewLabel[6] = StaticText8;
  m_PreviewPanel[7] = Panel9;
  m_PreviewLabel[7] = StaticText9;
  m_PreviewPanel[8] = Panel10;
  m_PreviewLabel[8] = StaticText10;
  m_PreviewPanel[9] = Panel11;
  m_PreviewLabel[9] = StaticText12;
  Panel1->SetCursor( *wxCROSS_CURSOR );
}

wxsImageListEditorDlg::~wxsImageListEditorDlg() {
  if( m_ImageDialog != NULL ) {
    delete m_ImageDialog;
  }
}


bool wxsImageListEditorDlg::Execute( wxString &inName, wxArrayString &aImageData ) {
  int         n;
  wxString    ss;
  if( aImageData.GetCount() < 2 ) {
    aImageData.Clear();
    aImageData.Add( _T( "16" ) );
    aImageData.Add( _T( "16" ) );
  }
  ArrayToImageList( aImageData, m_ImageList );
  m_ImportMask    = *wxWHITE;
  m_FirstImage    = 0;
  m_PreviewSelect = -1;
  StaticText15->SetLabel( inName );
  UpdateEnabled();
  n = ShowModal();
  if( n == wxID_OK ) {
    ImageListToArray( m_ImageList, aImageData );
  }
  return ( n == wxID_OK );
}


void wxsImageListEditorDlg::OnbAddClick( M_Code_unused wxCommandEvent &event ) {
  int         n;
  int         iw = 0, ih = 0;
  int         bw, bh;
  wxBitmap    *bmp;
  wxString    ss;
  if( !m_ImportImage.IsOk() ) {
    return;
  }
  n = m_ImageList.GetImageCount();
  if( n > 0 ) {
    m_ImageList.GetSize( 0, iw, ih );
  }
  bw = m_ImportImage.GetWidth();
  bh = m_ImportImage.GetHeight();
  if( n > 0 && ( ( bw > iw ) || ( bh > ih ) ) ) {
    n = ::wxMessageBox( _T( "The image is larger than the size allowed for the list;\nDivide the image into multiple entries?" ), _T( "Add Image" ), wxYES_NO );
    if( n != wxYES ) {
      return;
    }
  }
  bmp = new wxBitmap( m_ImportImage );
  if( cxTransparent->GetValue() ) {
    m_ImageList.Add( *bmp, m_ImportMask );
  } else {
    m_ImageList.Add( *bmp );
  }
  delete bmp;
  n = m_ImageList.GetImageCount();
  ss.Printf( _T( "%d" ), n );
  StaticText17->SetLabel( ss );
  PreviewList();
  UpdateEnabled();
}


void wxsImageListEditorDlg::OnbReadClick( M_Code_unused wxCommandEvent &event ) {
  int         n;
  wxBitmap    bmp;
  n = m_ImageDialog->ShowModal();
  if( n != wxID_OK ) {
    return;
  }
  bmp = m_ImageData.GetPreview( wxDefaultSize );
  m_ImportImage = bmp.ConvertToImage();
  m_ImportMask = *wxWHITE;
  PreviewImport();
}


void wxsImageListEditorDlg::PreviewImport( void ) {
  Panel1->Refresh();
}


void wxsImageListEditorDlg::PreviewList( void ) {
  int     i;
  for( i = 0; i < 10; i++ ) {
    m_PreviewPanel[i]->Refresh();
  }
}


void wxsImageListEditorDlg::OnPanel1Paint( M_Code_unused wxPaintEvent &event ) {
  int         iw, ih;
  wxPaintDC   dc( Panel1 );
  wxString    ss;
  if( !m_ImportImage.IsOk() ) {
    return;
  }
  wxImage img( m_ImportImage );
  if( cxTransparent->GetValue() ) {
    img.SetMaskColour( m_ImportMask.Red(), m_ImportMask.Green(), m_ImportMask.Blue() );
  }
  wxBitmap bmp( img );
  iw = bmp.GetWidth();
  ih = bmp.GetHeight();
  ss.Printf( _T( "%d x %d" ), iw, ih );
  StaticText23->SetLabel( ss );
  PaintPanel( dc, Panel1, bmp );
}


void wxsImageListEditorDlg::OnbColorClick( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxColourData    cd;
  wxColour        cc;
  if( !cxTransparent->GetValue() ) {
    return;
  }
  n = ColourDialog1->ShowModal();
  if( n != wxID_OK ) {
    return;
  }
  cd = ColourDialog1->GetColourData();
  cc = cd.GetColour();
  m_ImportMask = cc;
  bColor->SetBackgroundColour( cc );
  Panel1->Refresh();
}


void wxsImageListEditorDlg::OnPanel1LeftUp( wxMouseEvent &event ) {
  int         mx, my;
  wxClientDC  dc( Panel1 );
  wxColour    cc;
  if( !cxTransparent->GetValue() ) {
    return;
  }
  event.GetPosition( &mx, &my );
  dc.GetPixel( mx, my, &cc );
  m_ImportMask = cc;
  bColor->SetBackgroundColour( cc );
  Panel1->Refresh();
}


void wxsImageListEditorDlg::UpdateEnabled( void ) {
  int         n;
  int         w = 0, h = 0;
  bool        b;
  wxString    ss;
  b = cxTransparent->GetValue();
  bColor->Enable( b );
  StaticText21->Enable( b );
  n = m_ImageList.GetImageCount();
  ss.Printf( _T( "%d" ), n );
  StaticText17->SetLabel( ss );
  if( n > 0 ) {
    m_ImageList.GetSize( 0, w, h );
  }
  ss.Printf( _T( "%d" ), w );
  StaticText26->SetLabel( ss );
  ss.Printf( _T( "%d" ), h );
  StaticText27->SetLabel( ss );
  bDel->Enable( n > 0 );
  bClear->Enable( n > 0 );
  bSave->Enable( n > 0 );
}


void wxsImageListEditorDlg::OncxTransparentClick( M_Code_unused wxCommandEvent &event ) {
  UpdateEnabled();
  PreviewImport();
}


void wxsImageListEditorDlg::OnbOKClick( M_Code_unused wxCommandEvent &event ) {
  EndModal( wxID_OK );
}


void wxsImageListEditorDlg::OnbCancelClick( M_Code_unused wxCommandEvent &event ) {
  EndModal( wxID_CANCEL );
}


void wxsImageListEditorDlg::PaintPreviewPanel( wxPaintEvent &event ) {
  int         i;
  int         ip, ix;
  wxPanel     *pnl;
  wxBitmap    bmp;
  wxString    ss, tt;
  wxPaintDC   dc( ( wxWindow * ) event.GetEventObject() );
  ip = 0;
  pnl = ( wxPanel * ) event.GetEventObject();
  for( i = 0; i < 10; i++ ) {
    if( pnl == m_PreviewPanel[i] ) {
      ip = i;
    }
  };
  ix = m_FirstImage + ip;
  ss.Printf( _T( "%d" ), ix );
  m_PreviewLabel[ip]->SetLabel( ss );
  if( ix >= m_ImageList.GetImageCount() ) {
    return;
  }
  bmp = m_ImageList.GetBitmap( ix );
  PaintPanel( dc, pnl, bmp, ( ix == m_PreviewSelect ) );
}


void wxsImageListEditorDlg::OnbLeftClick( M_Code_unused wxCommandEvent &event ) {
  m_FirstImage -= 1;
  if( m_FirstImage < 0 ) {
    m_FirstImage = 0;
  }
  PreviewList();
}


void wxsImageListEditorDlg::OnbRightClick( M_Code_unused wxCommandEvent &event ) {
  int     n;
  m_FirstImage += 1;
  n = m_ImageList.GetImageCount();
  if( m_FirstImage >= n ) {
    m_FirstImage = n - 1;
  }
  if( m_FirstImage  < 0 ) {
    m_FirstImage = 0;
  }
  PreviewList();
}


void wxsImageListEditorDlg::OnPanel2LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 0 );
}


void wxsImageListEditorDlg::OnPanel3LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 1 );
}


void wxsImageListEditorDlg::OnPanel4LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 2 );
}


void wxsImageListEditorDlg::OnPanel5LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 3 );
}


void wxsImageListEditorDlg::OnPanel8LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 4 );
}


void wxsImageListEditorDlg::OnPanel6LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 5 );
}


void wxsImageListEditorDlg::OnPanel7LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 6 );
}


void wxsImageListEditorDlg::OnPanel9LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 7 );
}


void wxsImageListEditorDlg::OnPanel10LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 8 );
}


void wxsImageListEditorDlg::OnPanel11LeftUp( M_Code_unused wxMouseEvent &event ) {
  SelectPreviewPanel( 9 );
}


void wxsImageListEditorDlg::SelectPreviewPanel( int aIndex ) {
  int n = m_ImageList.GetImageCount() - 1;
  m_PreviewSelect = aIndex + m_FirstImage;
  if( m_PreviewSelect > n ) {
    m_PreviewSelect = n;
  }
  PreviewList();
  PreviewSelected();
}


void wxsImageListEditorDlg::OnPanel12Paint( M_Code_unused wxPaintEvent &event ) {
  wxPaintDC   dc( Panel12 );
  wxBitmap    bmp;
  wxString    ss, tt;
  if( ( m_PreviewSelect >= 0 ) &&
      ( m_ImageList.GetImageCount() > 0 ) ) {
    bmp = m_ImageList.GetBitmap( m_PreviewSelect );
  }
  ss.Printf( _T( "%d" ), m_PreviewSelect );
  StaticText28->SetLabel( ss );
  PaintPanel( dc, Panel12, bmp );
}


void wxsImageListEditorDlg::PreviewSelected( void ) {
  Panel12->Refresh();
}


void wxsImageListEditorDlg::OnbDelClick( M_Code_unused wxCommandEvent &event ) {
  int         n;
  wxString    ss;
  if( m_PreviewSelect < 0 ) {
    return;
  }
  ss.Printf( _T( "Delete Image %d; Are You Sure?" ), m_PreviewSelect );
  n = ::wxMessageBox( ss, _T( "Delete Image" ), wxYES_NO );
  if( n != wxYES ) {
    return;
  }
  m_ImageList.Remove( m_PreviewSelect );
  m_PreviewSelect = -1;
  PreviewList();
  PreviewSelected();
  UpdateEnabled();
}


void wxsImageListEditorDlg::OnbClearClick( M_Code_unused wxCommandEvent &event ) {
  int         n;
  wxString    ss;
  ss.Printf( _T( "Delete All Images. Are You Sure?" ) );
  n = ::wxMessageBox( ss, _T( "Delete Image" ), wxYES_NO );
  if( n != wxYES ) {
    return;
  }
  m_ImageList.RemoveAll();
  m_PreviewSelect = -1;
  PreviewList();
  PreviewSelected();
  UpdateEnabled();
}


void wxsImageListEditorDlg::OnbSaveClick( M_Code_unused wxCommandEvent &event ) {
  int         n;
  wxBitmap    bmp;
  wxString    ss;
  n = m_ImageList.GetImageCount();
  if( n == 0 ) {
    return;
  }
  if( m_PreviewSelect < 0 || m_PreviewSelect >= n ) {
    return;
  }
  bmp = m_ImageList.GetBitmap( m_PreviewSelect );
  n = FileDialog1->ShowModal();
  if( n == wxID_OK ) {
    ss = FileDialog1->GetPath();
    bmp.SaveFile( ss, wxBITMAP_TYPE_BMP );
  }
}


void wxsImageListEditorDlg::OnbSaveListClick( M_Code_unused wxCommandEvent& event ) {
  int         i, n;
  int         w, h;
  wxMemoryDC  dc;
  wxBitmap    *bmp;
  wxString    ss;
  n = m_ImageList.GetImageCount();
  if( n == 0 ) {
    return;
  }
  m_ImageList.GetSize( 0, w, h );
  bmp = new wxBitmap( n * w, h );
  dc.SelectObject( *bmp );
  dc.SetBackground( *wxWHITE_BRUSH );
  dc.Clear();
  for( i = 0; i < n; i++ ) {
    m_ImageList.Draw( i, dc, i * w, 0, wxIMAGELIST_DRAW_NORMAL, true );
  }
  n = FileDialog1->ShowModal();
  if( n == wxID_OK ) {
    ss = FileDialog1->GetPath();
    bmp->SaveFile( ss, wxBITMAP_TYPE_BMP );
  }
  delete bmp;
}


void wxsImageListEditorDlg::PaintPanel( wxPaintDC &aDC, wxPanel *aPanel, wxBitmap &aBitmap, bool aHot ) {
  int         iw, ih;
  int         pw, ph;
  double      sw, sh;
  int         x, y;
  wxBitmap    bmp;
  wxString    ss, tt;
  if( aPanel == NULL ) {
    return;
  }
  if( aHot ) {
    aDC.SetBackground( *wxBLUE_BRUSH );
  } else {
    aDC.SetBackground( *wxWHITE_BRUSH );
  }
  aDC.Clear();
  if( !aBitmap.Ok() ) {
    return;
  }
  iw = aBitmap.GetWidth();
  ih = aBitmap.GetHeight();
  if( ( iw < 0 ) || ( ih < 0 ) ) {
    return;
  }
  aPanel->GetClientSize( &pw, &ph );
  sw = 1.0;
  sh = 1.0;
  while( ( ( ( ( int )( sw * iw ) ) > pw ) || ( ( ( int )( sh * ih ) ) > ph ) ) && ( sw > 0.01 ) && ( sh > 0.01 ) ) {
    sw -= 0.01;
    sh -= 0.01;
  };
  while( ( ( int )( sw * iw ) ) < 8 ) {
    sw += 0.01;
  }
  while( ( ( int )( sh * ih ) ) < 8 ) {
    sh += 0.01;
  }
  aDC.SetUserScale( sw, sh );
  x = ( pw - ( ( int )( sw * iw ) ) ) / 2;
  y = ( ph - ( ( int )( sh * ih ) ) ) / 2;
  aDC.DrawBitmap( aBitmap, x, y, true );
  aDC.SetUserScale( 1.0, 1.0 );
}


void wxsImageListEditorDlg::ImageToArray( wxImage &inImage, wxArrayString &outArray ) {
  wxString                ss, tt;
  wxStringOutputStream    os;
  wxStringTokenizer       tkz;
  outArray.Clear();
  SaveXPM( &inImage, os );
  ss = os.GetString();
  tkz.SetString( ss, _T( "\r\n" ) );
  while( tkz.HasMoreTokens() ) {
    tt = tkz.GetNextToken();
    tt.Trim( true );
    tt.Trim( false );
    if( tt.Length() == 0 ) {
      continue;
    }
    if( tt.StartsWith( _T( "/*" ) ) ) {
      continue;
    }
    if( tt.StartsWith( _T( "//" ) ) ) {
      continue;
    }
    outArray.Add( tt );
  };
}

void wxsImageListEditorDlg::ArrayToImage( wxArrayString &inArray, wxImage &outImage ) {
  int                     i, n;
  wxString                ss, tt;
  wxStringInputStream     *ns;
  n = CalcArraySize( inArray );
  if( inArray.Item( 0 ).Find( _T( "XPM" ) ) < 0 ) {
    tt += _T( "/* XPM */n" );
  }
  tt.Alloc( n + 64 );
  for( i = 0; i < ( int )inArray.GetCount(); i++ ) {
    ss = inArray.Item( i );
    n = ss.Length();
    if( n == 0 ) {
      continue;
    }
    tt += ss;
    tt += _T( "\n" );
  }
  ns = new wxStringInputStream( tt );
  outImage.LoadFile( *ns, wxBITMAP_TYPE_XPM );
  delete ns;
}


void wxsImageListEditorDlg::BitmapToArray( wxBitmap &inBitmap, wxArrayString &outArray ) {
  wxImage     img;
  img = inBitmap.ConvertToImage();
  ImageToArray( img, outArray );
}


void wxsImageListEditorDlg::ArrayToBitmap( wxArrayString &inArray, wxBitmap &outBitmap ) {
  wxImage     img;
  wxBitmap    *bmp;
  ArrayToImage( inArray, img );
  bmp = new wxBitmap( img );
  outBitmap = ( *bmp );
}


void wxsImageListEditorDlg::ImageListToArray( wxImageList &inList, wxArrayString &outArray ) {
  int             i, j, k, n;
  wxBitmap        bmp;
  wxArrayString   aa;
  wxString        ss, tt;
  outArray.Clear();
  n = inList.GetImageCount();
  if( n == 0 ) {
    return;
  }
  inList.GetSize( 0, i, j );
  ss.Printf( _T( "%d" ), i );
  outArray.Add( ss );
  ss.Printf( _T( "%d" ), j );
  outArray.Add( ss );
  for( i = 0; i < n; i++ ) {
    bmp = inList.GetBitmap( i );
    BitmapToArray( bmp, aa );
    k = aa.GetCount();
    for( j = 0; j < k; j++ ) {
      ss = aa.Item( j );
      outArray.Add( ss );
    }
  }
}


void wxsImageListEditorDlg::ArrayToImageList( wxArrayString &inArray, wxImageList &outList ) {
  int             i;
  int             w, h;
  long            ll;
  wxBitmap        bmp;
  wxArrayString   aa;
  wxString        ss, tt;
  w = 16;
  if( inArray.GetCount() >= 1 ) {
    ss = inArray.Item( 0 );
    if( ss.ToLong( &ll ) ) {
      w = ll;
    }
  }
  h = 16;
  if( inArray.GetCount() >= 2 ) {
    ss = inArray.Item( 1 );
    if( ss.ToLong( &ll ) ) {
      h = ll;
    }
  }
  outList.RemoveAll();
  outList.Create( w, h, 128 );
  aa.Clear();
  i = 2;
  while( i < ( int )inArray.GetCount() ) {
    ss = inArray.Item( i );
    i += 1;
    ss.Trim( true );
    ss.Trim( false );
    if( ss.Length() == 0 ) {
    } else if( ss.Find( _T( "xpm_data" ) ) < 0 ) {
      aa.Add( ss );
    } else if( aa.GetCount() == 0 ) {
    } else {
      ArrayToBitmap( aa, bmp );
      outList.Add( bmp );
      aa.Clear();
      aa.Add( ss );
    }
  }
  if( aa.GetCount() > 0 ) {
    ArrayToBitmap( aa, bmp );
    outList.Add( bmp );
    aa.Clear();
  }
}


void wxsImageListEditorDlg::CopyImageList( wxImageList &inList, wxImageList &outList ) {
  int         i, n;
  int         w, h;
  wxBitmap    bmp;
  inList.GetSize( 0, w, h );
  n = inList.GetImageCount();
  outList.RemoveAll();
  outList.Create( w, h, n );
  for( i = 0; i < n; i++ ) {
    bmp = inList.GetBitmap( i );
    outList.Add( bmp );
  }
}


wxsItem     *wxsImageListEditorDlg::FindTool( wxsItem *inItem, wxString inName ) {
  int             i, n;
  wxsItemResData  *res;
  wxsTool         *tool;
  wxsTool         *found;
  wxString        ss, tt;
  static wxsItem  *last_item;
  if( inItem != NULL ) {
    last_item = inItem;
  }
  if( last_item == NULL ) {
    return NULL;
  }
  found = NULL;
  res = last_item->GetResourceData();
  n = res->GetToolsCount();
  for( i = 0; i < n; i++ ) {
    tool = res->GetTool( i );
    ss = tool->GetVarName();
    if( ss == inName ) {
      found = tool;
    }
  }
  return found;
}


int     wxsImageListEditorDlg::CalcArraySize( wxArrayString &inArray ) {
  int     i, n;
  n = 0;
  for( i = 0; i < ( int )inArray.GetCount(); i++ ) {
    n += inArray.Item( i ).Length() + 1;
  }
  return n;
}


bool wxsImageListEditorDlg::SaveXPM( wxImage *image, wxOutputStream &stream ) {
#define MaxCixels  90
  static const char Cixel[MaxCixels + 1] =
    "_.XoO+@#$&*=-;:>,<1234567890qwertyuipasdfghjk"
    "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()`'][{}|";
  int i, j, k;
  wxImageHistogram histogram;
  int cols = int( image->ComputeHistogram( histogram ) );
  int chars_per_pixel = 1;
  for( k = MaxCixels; cols > k; k *= MaxCixels ) {
    chars_per_pixel++;
  }
  wxString sName;
  if( image->HasOption( wxIMAGE_OPTION_FILENAME ) ) {
    wxSplitPath( image->GetOption( wxIMAGE_OPTION_FILENAME ), NULL, &sName, NULL );
    sName << wxT( "_xpm" );
  }
  if( !sName.empty() ) {
    sName = wxString( wxT( "/* XPM */\nstatic const char *" ) ) + sName;
  } else {
    sName = wxT( "/* XPM */\nstatic const char *xpm_data" );
  }
  stream.Write( ( const char * ) sName.ToAscii(), sName.Len() );
  char tmpbuf[200];
  sprintf( tmpbuf,
           "[] = {\n"
           "/* columns rows colors chars-per-pixel */\n"
           "\"%i %i %i %i\",\n",
           image->GetWidth(), image->GetHeight(), cols, chars_per_pixel );
  stream.Write( tmpbuf, strlen( tmpbuf ) );
  char *symbols_data = new char[cols * ( chars_per_pixel + 1 )];
  char **symbols = new char*[cols];
  unsigned long mask_key = 0x1000000 ;
  if( image->HasMask() )
    mask_key = ( image->GetMaskRed() << 16 ) |
               ( image->GetMaskGreen() << 8 ) | image->GetMaskBlue();
  for( wxImageHistogram::iterator entry = histogram.begin();
       entry != histogram.end(); ++entry ) {
    unsigned long index = entry->second.index;
    symbols[index] = symbols_data + index * ( chars_per_pixel + 1 );
    char *sym = symbols[index];
    for( j = 0; j < chars_per_pixel; j++ ) {
      sym[j] = Cixel[index % MaxCixels];
      index /= MaxCixels;
    }
    sym[j] = '\0';
    unsigned long key = entry->first;
    if( key == 0 ) {
      sprintf( tmpbuf, "\"%s c Black\",\n", sym );
    } else if( key == mask_key ) {
      sprintf( tmpbuf, "\"%s c None\",\n", sym );
    } else {
      wxByte r = wxByte( key >> 16 );
      wxByte g = wxByte( key >> 8 );
      wxByte b = wxByte( key );
      sprintf( tmpbuf, "\"%s c #%02X%02X%02X\",\n", sym, r, g, b );
    }
    stream.Write( tmpbuf, strlen( tmpbuf ) );
  }
  stream.Write( "/* pixels */\n", 13 );
  unsigned char *data = image->GetData();
  for( j = 0; j < image->GetHeight(); j++ ) {
    char tmp_c;
    tmp_c = '\"';
    stream.Write( &tmp_c, 1 );
    for( i = 0; i < image->GetWidth(); i++, data += 3 ) {
      unsigned long key = ( data[0] << 16 ) | ( data[1] << 8 ) | ( data[2] );
      stream.Write( symbols[histogram[key].index], chars_per_pixel );
    }
    tmp_c = '\"';
    stream.Write( &tmp_c, 1 );
    if( j + 1 < image->GetHeight() ) {
      tmp_c = ',';
      stream.Write( &tmp_c, 1 );
    }
    tmp_c = '\n';
    stream.Write( &tmp_c, 1 );
  }
  stream.Write( "};\n", 3 );
  delete[] symbols;
  delete[] symbols_data;
  return true;
}
